this.BX=this.BX||{};(function(e,t,n,i,a,r,o,l){"use strict";var s=function(){function e(t){babelHelpers.classCallCheck(this,e);this.element=t.element;this.selector=t.selector;this.cardSelector=t.cardSelector;this.onHover=t.onHover;this.pseudoElement=l.Dom.hasClass(this.element,"landing-designer-block-pseudo-last");l.Event.bind(this.element,"mouseover",this.onMouseOver.bind(this));if(t.className){l.Dom.addClass(this.element,t.className)}}babelHelpers.createClass(e,[{key:"isPseudoElement",value:function e(){return this.pseudoElement}},{key:"getSelector",value:function e(){return(this.cardSelector?this.cardSelector+" ":"")+this.selector}},{key:"getCardSelector",value:function e(){return this.cardSelector}},{key:"getOriginalSelector",value:function e(){return this.selector}},{key:"getElement",value:function e(){return this.element}},{key:"onMouseOver",value:function e(t){t.stopPropagation();this.onHover(this)}}]);return e}();var d,c,u;var h=function(){function e(){babelHelpers.classCallCheck(this,e)}babelHelpers.createClass(e,null,[{key:"getHoverDiv",value:function e(){return l.Tag.render(d||(d=babelHelpers.taggedTemplateLiteral(['<div class="landing-designer-block-node-hover"></div>'])))}},{key:"getPseudoLast",value:function e(){return l.Tag.render(c||(c=babelHelpers.taggedTemplateLiteral(['<div class="landing-designer-block-pseudo-last"></div>'])))}},{key:"getAddNodeButton",value:function e(){return l.Tag.render(u||(u=babelHelpers.taggedTemplateLiteral(['\n\t\t\t<div class="landing-designer-block-node-hover-add">\n\t\t\t\t<span class="landing-designer-block-node-hover-add-title">\n\t\t\t\t\t',"\n\t\t\t\t</span>\n\t\t\t</div>"])),r.Loc.getMessage("LANDING_DESIGN_BLOCK_REPO_BUTTON"))}}]);return e}();var g;var v=function(e){babelHelpers.inherits(t,e);function t(e){var n;babelHelpers.classCallCheck(this,t);n=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,"design_repo",{title:r.Loc.getMessage("LANDING_DESIGN_BLOCK_REPO_TITLE"),scrollAnimation:true}));n.currentCategory=null;n.cache=new l.Cache.MemoryCache;n.onElementSelect=e.onElementSelect;n.renderTo(parent.document.body?parent.document.body:document.body);l.Dom.addClass(n.layout,"landing-ui-panel-repo");return n}babelHelpers.createClass(t,[{key:"addRepository",value:function e(t){var n=this;t.map((function(e){n.addElement(e)}))}},{key:"makeElementUnique",value:function e(t){var n=this;var i={};Object.keys(t.manifest.nodes).map((function(e){var a="-"+n.randomNum(1e3,9999);var r=e.substr(1);t.html=t.html.replaceAll(new RegExp(r+'([\\s"]{1})',"g"),r+a+"$1");i[e+a]=t.manifest.nodes[e]}));t.manifest.nodes=i;return t}},{key:"addElement",value:function e(t){var n=this;var i=new BX.Landing.UI.Card.BlockPreviewCard({title:t.name,image:"/bitrix/images/landing/designerblock/presets/"+t.code+".jpg",onClick:function e(){n.onElementSelect(n.makeElementUnique(t));void n.hide()}});this.appendCard(i)}},{key:"randomNum",value:function e(t,n){return parseInt(Math.random()*(n-t)+t)}},{key:"getListContainer",value:function e(){return this.cache.remember("listContainer",(function(){return l.Tag.render(g||(g=babelHelpers.taggedTemplateLiteral(['<div class="landing-ui-field-layer-list-container"></div>'])))}))}}]);return t}(o.Content);var p=function(){function e(t){babelHelpers.classCallCheck(this,e);this.panel=new v({onElementSelect:t.onElementSelect});this.panel.addRepository(t.repository)}babelHelpers.createClass(e,[{key:"showPanel",value:function e(){this.panel.show().then()}}]);return e}();var m,b,f;var y=function(){function e(t,r){var o=this;babelHelpers.classCallCheck(this,e);babelHelpers.defineProperty(this,"hoverArea",null);babelHelpers.defineProperty(this,"activeNode",null);babelHelpers.defineProperty(this,"changed",false);babelHelpers.defineProperty(this,"saving",false);if(!t){return}this.originalNode=t;this.blockNode=t.children[0];this.blockCode=r.code;this.blockId=r.id;this.designed=r.designed;this.autoPublicationEnabled=r.autoPublicationEnabled;this.landingId=r.lid;this.nodes=r.manifest.nodes;this.highlight=new a.Highlight;this.cardSelectors=r.manifest.cards?Object.keys(r.manifest.cards):[];this.designAllowed=!!n.Env.getInstance().getOptions().design_block_allowed;this.cardSelectors.push("");this.nodeMap=new WeakMap;this.metrika=new i.Metrika(true);this.repoManager=new p({repository:r.repository,onElementSelect:this.addElement.bind(this)});this.saveButton=parent.document.getElementById("landing-design-block-save")||top.document.getElementById("landing-design-block-save")||document.getElementById("landing-design-block-save");BX.addCustomEvent("Landing.Editor:load",(function(){o.preventEvents();o.initHistoryEvents();o.initTopPanel();o.initNodes();o.initGrid();o.initSliders();o.initHoverArea()}))}babelHelpers.createClass(e,[{key:"clearHtml",value:function e(t){return t.replace(/<div class="[^"]*landing-designer-block-pseudo-last[^"]*"[^>]*>[\s]*<\/div>/g,"").replace(/<div class="[^"]*landing-highlight-border[^"]*"[^>]*>[\s]*<\/div>/g,"").replace(/url\(&quot;(.*?)&quot;\)/g,"url($1)").replace(/\s*data-(landingwrapper)="[^"]+"\s*/g," ").replace(/\s*[\w-_]+--type-wrapper\s*/g," ").replace(/<div[\s]*>[\s]*<\/div>/g,"").replace(/\s*style=""/g,"")}},{key:"preventEvents",value:function e(){var t=this;var n={a:"click",form:"submit",input:"keydown"};Object.keys(n).map((function(e){babelHelpers.toConsumableArray(t.blockNode.querySelectorAll(e)).map((function(t){l.Event.bind(t,n[e],(function(e){e.preventDefault()}))}))}))}},{key:"initHistoryEvents",value:function e(){var n=this;BX.Landing.History.getInstance().setTypeDesignerBlock(this.blockId).then((function(){return t.Backend.getInstance().action("History::clearDesignerBlock",{blockId:n.blockId})}));var i=this.getDocumentBody();top.BX.addCustomEvent("Landing:onHistoryAddNode",(function(e){var t=false;e.map((function(e){var n=e.insertAfterSelector||null;var a=e.parentNodeSelector||null;var r=l.Tag.render(m||(m=babelHelpers.taggedTemplateLiteral(["",""])),e.elementHtml);if(n){t=true;l.Dom.insertAfter(r,i.querySelector(n))}else if(a){t=true;l.Dom.prepend(r,i.querySelector(a))}}));if(t){n.refreshManifest();setTimeout((function(){n.sendLabel("designerBlock","onHistoryAddNode")}),0)}}));top.BX.addCustomEvent("Landing:onHistoryRemoveNode",(function(e){e.map((function(e){n.removeNode(i.querySelector(e.elementSelector))}));n.refreshManifest();setTimeout((function(){n.sendLabel("designerBlock","onHistoryRemoveNode")}),0)}))}},{key:"initTopPanel",value:function e(){var n=this;l.Event.bind(this.saveButton,"click",(function(){n.highlight.hide(true);var e=function e(){if(BX.SidePanel&&BX.SidePanel.Instance){BX.SidePanel.Instance.close()}};if(!n.changed){e();return}if(!n.designAllowed){top.BX.UI.InfoHelper.show("limit_crm_free_superblock1");return}n.saving=true;var i={};i["Block::updateContent"]={action:"Block::updateContent",data:{lid:n.landingId,block:n.blockId,content:n.clearHtml(n.originalNode.innerHTML).replaceAll(' style="',' bxstyle="'),designed:1}};if(n.autoPublicationEnabled){i["Landing::publication"]={action:"Landing::publication",data:{lid:n.landingId}}}i["History::clearDesignerBlock"]={action:"History::clearDesignerBlock",data:{blockId:n.blockId}};t.Backend.getInstance().batch("Block::updateContent",i).then((function(){n.saving=false;e()}));n.sendLabel("designerBlock","save"+"&designed="+(n.designed?"Y":"N")+"&code="+n.blockCode)}))}},{key:"initNodes",value:function e(){var t=this;Object.keys(this.nodes).map((function(e){t.cardSelectors.map((function(n){babelHelpers.toConsumableArray(t.blockNode.querySelectorAll((n?n+" ":"")+e)).map((function(i){if(t.nodes[e]["useInDesigner"]===false){return}t.addNode({element:i,selector:e,cardSelector:n,type:t.nodes[e]["type"]})}))}))}))}},{key:"initGrid",value:function e(){var t=this;Object.keys(this.nodes).map((function(e){t.cardSelectors.map((function(n){babelHelpers.toConsumableArray(t.blockNode.querySelectorAll((n?n+" ":"")+e)).map((function(i){if(t.nodes[e]["useInDesigner"]===false){return}var a=t.nodes[e]["type"]==="icon"?i.parentNode.parentNode:i.parentNode;if(l.Dom.attr(a,"data-landingWrapper")){return}var r=h.getPseudoLast();l.Dom.attr(a,"data-landingWrapper",true);l.Dom.append(r,a);t.addNode({cardSelector:n,element:r,className:e.substr(1)+"-last",selector:e+"-last"})}))}))}))}},{key:"initSliders",value:function e(){var t=".js-carousel";babelHelpers.toConsumableArray(this.blockNode.querySelectorAll(t)).map((function(e){var t=(l.Text.toNumber(e.dataset.slidesShow)||1)*(l.Text.toNumber(e.dataset.rows)||1);var n=".".concat(babelHelpers.toConsumableArray(e.classList).join(".")," .js-slide:not(:nth-child(-n+").concat(t,"))");document.head.appendChild(l.Tag.render(b||(b=babelHelpers.taggedTemplateLiteral(["<style>","{display: none !important;}</style>"])),n))}))}},{key:"initHoverArea",value:function e(){var t=this;if(this.hoverArea){return}this.hoverArea=h.getHoverDiv();var n=h.getAddNodeButton();var i=BX.Landing.UI.Button.CardAction;var a=BX.Landing.UI.Panel.BaseButtonPanel;var r=new a("nodeAction","landing-ui-panel-block-card-action");l.Event.bind(n,"click",(function(){t.repoManager.showPanel();t.hideHoverArea()}));r.addButton(new i("remove",{html:"&nbsp;",onClick:this.removeElement.bind(this)}));void r.show();l.Dom.append(n,this.hoverArea);l.Dom.append(r.layout,this.hoverArea);l.Dom.append(this.hoverArea,this.getDocumentBody());l.Event.bind(this.blockNode,"mouseover",(function(){t.hideHoverArea()}))}},{key:"adjustHoverArea",value:function e(){if(!this.hoverArea){return}this.showHoverArea();var t=this.activeNode.getElement().getBoundingClientRect();var n=this.hoverArea.querySelector(".landing-designer-block-node-hover-add");var i=this.hoverArea.querySelector('div[data-id="nodeAction"]');var a=BX.Landing.PageObject.getEditorWindow();if(i){if(this.activeNode.isPseudoElement()){l.Dom.hide(i)}else{l.Dom.show(i)}}if(n){l.Dom.style(n,{top:t.height-5+"px"})}l.Dom.style(this.hoverArea,{top:t.top+a.scrollY+"px",left:t.left+(t.width<30?30:0)+"px",width:t.width+"px",height:"35px"})}},{key:"showHoverArea",value:function e(){if(this.hoverArea){l.Dom.show(this.hoverArea)}}},{key:"hideHoverArea",value:function e(){var t=this;if(this.hoverArea){setTimeout((function(){l.Dom.hide(t.hoverArea)}),0)}}},{key:"refreshManifest",value:function e(t){var n=this;if(t){Object.keys(t).map((function(e){n.nodes[e]=t[e]}))}this.initNodes();this.initGrid()}},{key:"getDocumentBody",value:function e(){return document.body}},{key:"isInsideElement",value:function e(t){return t.parentElement.tagName==="A"}},{key:"sendLabel",value:function e(t,n){this.metrika.clearSendedLabel();this.metrika.sendLabel(null,t,n)}},{key:"addElement",value:function e(n){var i=this;var a=this.activeNode;var r=[];babelHelpers.toConsumableArray(document.body.querySelectorAll(a.getSelector())).map((function(e){var t=n.html;var a=l.Tag.render(f||(f=babelHelpers.taggedTemplateLiteral(["",""])),t);var o=i.isInsideElement(e)?e.parentNode:e;l.Dom.insertAfter(a,o);r.push({elementHtml:t,elementSelector:BX.Landing.Utils.getCSSSelector(a),insertAfterSelector:BX.Landing.Utils.getCSSSelector(o)})}));this.sendLabel("designerBlock","addElement"+"&code="+this.blockCode+"&name="+n.code+"&preset="+(Object.keys(n.manifest.nodes).length===1?"N":"Y"));this.changed=true;this.refreshManifest(n.manifest.nodes);this.highlight.show(null);t.Backend.getInstance().action("History::pushDesignerBlock",{blockId:this.blockId,action:"ADD_NODE",data:{tags:r}}).then((function(e){BX.Landing.History.getInstance().push()}))}},{key:"removeElement",value:function e(){var n=this;var i=[];this.hideHoverArea();this.highlight.hide();setTimeout((function(){n.sendLabel("designerBlock","removeElement"+"&tagName="+n.activeNode.getElement().tagName+"&code="+n.blockCode);babelHelpers.toConsumableArray(document.body.querySelectorAll(n.activeNode.getSelector())).map((function(e){i.push({elementHtml:n.clearHtml(e.outerHTML),elementSelector:BX.Landing.Utils.getCSSSelector(e),insertAfterSelector:e.previousElementSibling?BX.Landing.Utils.getCSSSelector(e.previousElementSibling):null,parentNodeSelector:BX.Landing.Utils.getCSSSelector(e.parentNode)});n.removeNode(e)}));n.changed=true;n.refreshManifest();t.Backend.getInstance().action("History::pushDesignerBlock",{blockId:n.blockId,action:"REMOVE_NODE",data:{selector:n.activeNode.getOriginalSelector(),tags:i}}).then((function(e){BX.Landing.History.getInstance().push()}))}),0)}},{key:"typeWithWrapper",value:function e(t){return t==="icon"||t==="embed"}},{key:"addNode",value:function e(t){if(!this.nodeMap.get(t.element)){if(t.selector.match(/^\.[\w-_]+$/i)===null){return false}var n=this.typeWithWrapper(t.type);t.element=n?t.element.parentNode:t.element;if(n){t.selector=t.selector+"--type-wrapper";l.Dom.addClass(t.element,t.selector.substr(1))}t.onHover=this.onMouseOver.bind(this);this.nodeMap.set(t.element,new s(t));return true}return false}},{key:"removeNode",value:function e(t){if(t){l.Dom.remove(t);this.nodeMap["delete"](t)}}},{key:"onMouseOver",value:function e(t){if(this.saving){return}this.activeNode=t;this.adjustHoverArea();if(!t.isPseudoElement()){this.highlight.show(t.getElement())}}}]);return e}();e.DesignerBlock=y})(this.BX.Landing=this.BX.Landing||{},BX.Landing,BX.Landing,BX.Landing,BX.Landing.UI,BX.Landing,BX.Landing.UI.Panel,BX);
//# sourceMappingURL=designerblock.bundle.map.js